(in-package :moneychanger)

(defclass currency ()
  ((country :initarg :country
	    :accessor country)
   (name :initarg :name
	 :accessor name)
   (rate :initarg :rate
	 :accessor rate))
  (:documentation "The currency rate for a country"))

(defmethod print-object ((obj currency) stream)
  (print-unreadable-object (obj stream :type t)
    (with-slots (country name rate) obj
      (format stream "~A (~A): ~D"
	      name country rate))))

;; Currencies should be textually presented like this:
;; Peso (Mexico)
(define-presentation-method present (object (type currency)
					    stream (view textual-view)
					    &key &allow-other-keys)
  (with-text-face (stream :bold)
    (princ (name object) stream))
  (format stream " (~A)"
	  (country object)))

(defmethod convert-to-usd ((currency currency) amount)
  "Convert an amount of money in a currency to US Dollars"
  (/ amount (rate currency)))

(defmethod convert-from-usd ((currency currency) amount)
  "Convert US Dollars to a currency"
  (* amount (rate currency)))